package data

import (
	"log"
	"stormragetech/dawn/conf"
	"time"

	"gopkg.in/mgo.v2"
)

var session *mgo.Session

//Conn 连接全局变量
var Conn *mgo.Collection

func init() {
	log.Printf("------ mongo服务器地址为: %v", []string{conf.Conf.MongoAddr})
	dialInfo := &mgo.DialInfo{
		Addrs:     []string{conf.Conf.MongoAddr},
		Direct:    false,
		Timeout:   time.Second * 1,
		PoolLimit: 4096,
	}
	var err error
	session, err = mgo.DialWithInfo(dialInfo)
	if err != nil {
		log.Println(err.Error())
	}
	// defer session.Close()
}

// GetConn Mongo连接指定数据库及表
func GetConn(d string, c string) {
	Conn = session.DB(d).C(c)
}
